<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/utilities/xajax/xajax_core/xajax.inc.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/gui/presenter/PresenterCreateNews.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php';
		
	$debug = FirePHP :: getInstance(true);
	$debug -> setEnabled(true);
	
	//Permite eliminar los notices
	error_reporting (E_ALL ^ E_NOTICE);
	
	$_SESSION['debug'] = $debug;
	
	$xajax = new xajax(); 
	 
	$xajax -> register(XAJAX_FUNCTION, 'clickCreateNews');
	 
	$xajax -> processRequest(); 
	 
	$xajax -> configure('javascript URI','../../../utilities/xajax/');
	
	function clickCreateNews($news) {
	
	   $presenterCreateNews = new PresenterCreateNews();
		$GLOBALS['debug'] -> log("DATOS DE LA VISTA NEWS");
		$GLOBALS['debug'] -> log($news, "newsDate");
	    $GLOBALS['debug'] -> log($news, "imagePath");
		$GLOBALS['debug'] -> log($news, "title");
		$GLOBALS['debug'] -> log($news, "description");
	
		$newsCreation = $presenterCreateNews -> clickCreateNews ($news);
		
		$response = new xajaxResponse();
		
		if ($newsCreation == false)
			$response -> assign("transactionResult", "innerHTML", 
				'<font size="+1" color="#FF0000">La operaci&oacute;n fall&oacute;</font>');
		
		else
			$response -> assign("transactionResult", "innerHTML", 
				'<font size="+1" color="#006600">Operaci&oacute;n exitosa</font>');
		
		return $response;
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registre una nueva sucursal</title>
<?php 
	$xajax->printJavascript("../../../utilities/xajax/"); 
?>
<link rel="stylesheet" type="text/css" href="../css/formsStyles.css"/>
<link rel="stylesheet" type="text/css" href="../css/styles2.css" />
<!--Hoja de estilos del calendario -->
<link rel="stylesheet" type="text/css" media="all" href="../jscalendar/calendar-blue.css" title="win2k-cold-1" />

<!-- librería principal del calendario -->
<script type="text/javascript" src="../jscalendar/calendar.js"></script>

<!-- librería para cargar el lenguaje deseado -->
<script type="text/javascript" src="../jscalendar/lang/calendar-es.js"></script>

<!-- librería que declara la función Calendar.setup, que ayuda a generar un calendario en unas pocas líneas de código -->
<script type="text/javascript" src="../jscalendar/calendar-setup.js"></script> 

<!-- include the Tools -->
<script src="http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js"></script>

</head>
<body>
	<div id="formsContainer">
        <div id="title">Registre una nueva Noticia</div><br />
        <form name="news" id="news">
            <table class="formTable" cellspacing="0" cellpadding="5">
                <tr class="even">
                   <td align="right">Fecha</td>
                    <td align="left">
                        <input type="text" id="newsDate" name="newsDate" 
                        	readonly="readonly" size="32" />&nbsp;
                        <input type="button" id="launcher" value="..." />
                    </td>
                
                    <td align="right">Imagen</td>
                    <td align="left">
                        <input type="file" name="imagePath" size="32" maxlength="30" />
                    </td>
                </tr>
                
                <tr class="odd">
                   <td align="right">Titulo</td>
                    <td align="left">
                        <input type="text" name="title" size="32" maxlength="30" />
                    </td>
                  
                     <td align="right">Descripcion</td>
                    <td align="left">
                        <input type="text" name="description" size="32" maxlength="30" />
                    </td>
                </tr>
            </table>
            
            <div id="transactionResult" align="center"></div>
            
            <br /><div id="buttons" align="center">
            	<input type="button" name="buttonCreateNews" value="Registrar" onclick="xajax_clickCreateNews(xajax.getFormValues('news'))" />
            </div>
        </form>
    </div>
    
        <!-- script que define y configura el calendario-->
     <script type="text/javascript">
    	Calendar.setup({
			inputField:"newsDate",
			ifFormat:"%Y-%m-%d",
			button:"launcher"
		});
    </script> 
  
	
	</script>
</body>
</html>